package com.peng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peng.pojo.Admin;
import com.peng.pojo.LoginForm;
import com.peng.service.AdminService;
import com.peng.mapper.AdminMapper;
import com.peng.utils.MD5;
import com.peng.utils.Result;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author dell
 * @description 针对表【tb_admin】的数据库操作Service实现
 * @createDate 2022-05-15 13:37:12
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {


    @Override
    public Admin login(LoginForm loginForm) {
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Admin::getName,loginForm.getUsername());
        queryWrapper.eq(Admin::getPassword, MD5.encrypt(loginForm.getPassword()));
        queryWrapper.last("limit 1");
        Admin admin = baseMapper.selectOne(queryWrapper);
        return admin;
    }

    @Override
    public IPage<Admin> getAllAdmin(Integer pageNo, Integer pageSize, String adminName) {
        Page<Admin> adminPage = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(adminName))
            queryWrapper.like(Admin::getName,adminName);
        Page<Admin> adminPage1 = baseMapper.selectPage(adminPage, queryWrapper);
        return adminPage1;
    }


}




